package com.hr.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * 档案
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Archive
{
    @Id
    private int id;
    private String name;
    private String sex;
    private String mail;
    private String intro;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
    private Date date=new Date();
    private boolean pub;
    private String tel;
    private String policy;
    private String area;
    private String degree;
    private String school;
    private String major;
    private int age;

    private List<Talent> talents=new ArrayList<>();
    private List<Position> positions=new ArrayList<>();
    private List<Deed> deeds=new ArrayList<>();
    private List<Evaluate> evaluates=new ArrayList<>();

    public void cutPosition()//处理冗余
    {
        Iterator<Position> positionIterator=positions.iterator();

        while(positionIterator.hasNext())
        {
            Position position=positionIterator.next();

            if(position.getDepartment()==null|| position.getDepartment().getId()!=id)
            {
                positionIterator.remove();
            }else
            {
                position.setCompany(null);
                position.setDepartment(null);
            }


        }
//        for(Position position:positions)
//        {
//            if(position.getDepartment()==null|| position.getDepartment().getId()!=id)
//            {
//                position=null;
//            }else
//            {
//                position.setCompany(null);
//                position.setDepartment(null);
//            }
//        }
    }

    public void cutTail()
    {
        talents=new ArrayList<>();
        positions=new ArrayList<>();
        deeds=new ArrayList<>();
        evaluates=new ArrayList<>();
    }
}
